<?php
namespace Common\Taglib;

class questionview
{
    public function run($opt)
    {
        $id = intval($opt['id']);
        $field = trim($opt['field']);
        $question = D('Question');
        $item = $question->get_question_one($id);
        $question->edit_click($item['id']);//更新问题点击次数
        D('Answer')->edit_click($item['id']);//更新答案点击次数
        $item['describe'] = ytata_strip_tags($item['describe']);
        $item['addtime_str'] = daterange($item['addtime']);
        $user = D('User')->get_user_one($item['uid'],true,1);//获取用户名
		$item['adduser']=$user;
        $item['username'] = $user['username'];
        $item['userurl'] = D('User')->user_url($item['uid']);//用户名链接
        $item['tag'] = D('QuestionTag')->get_tag_qid($item['id']);//获取标签
        $item['img'] = D('QuestionImg')->get_img_qid($item['id']);//获取图片
        $item['supp'] = D('QuestionSupp')->get_question_supp($item['id'], $item['uid']);//获取问题补充
        $task = D('Task')->get_task_one(11);//查找任务积分规定，答案被采纳获取的积分
        $item['sys_reply_gold'] = intval($task['gold']);//系统奖励积分
        $item['sys_reply_exp'] = intval($task['exp']);//系统奖励经验

        $item['is_reply'] = 0;
        $uid = session('ytata.uid');
        //判断是否回答过
        if (!empty($uid)) {
            $info = D('Answer')->get_answer_one($id, $uid);
            if (!empty($info)) {
                $asked = D('AnswerReply')->get_answer_reply($info['id']);
                if (!empty($asked))//如果有追问
                {
                    $info['asked'] = $asked;
                }
                $info['content'] = ytata_strip_tags($info['content']);
                $item['is_reply'] = 1;//已经回答过
                $item['my_reply'] = $info;
            }
        }
        $item['follow_count'] = D('FollowQuestion')->get_follow_count($id);
        //是否关注过
        $item['is_follow'] = 0;
        if (!empty($uid)) {
            $chenk = D('FollowQuestion')->chenk_follow_question($uid, $id);
            if ($chenk) {
                $item['is_follow'] = 1;
            }
        }
        $item['favorites_count'] = D('UserFavorites')->get_favorites_count($id, 1);
        //是否收藏过
        $item['is_favorites'] = 0;
        if (!empty($uid)) {
            $chenk = D('UserFavorites')->chenk_favorites($uid, $id);
            if ($chenk) {
                $item['is_favorites'] = 1;
            }
        }
//        dump($item);
        return $item;
    }
}